<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Admin/classes/PhpFox_ComponentWhosOnline.class.php, $Author:  $ */



/** Component Whos Online
 *
 * Parameters:
 * 1. iNumLastSessions (optional) - number of last users (by default - 10)
 *
 *
 * @version $Id: PhpFox_ComponentWhosOnline.class.php 482 2008-08-15 11:29:00Z phpfoxsv $
 * @package module.admin
 */
class PhpFox_Mod_Admin_ComponentWhosOnline extends BaseComponent
{
    /** Process
     */
    function process()
    {
    	App::loadClass('Pager');

        $oSrvAdmin = $this->_oModule->getService('Admin');
        /* @var $oSrvAdmin PhpFox_Mod_Admin_ServiceAdmin */

        $oUrl = &App::getUrl();

        $oReq = &App::getRequest();

        $oTpl = &$this->_oModule->getTemplate();

        $oSrvLog = App::getModuleService('Log', 'Log');
        /* @var $oSrvLog PhpFox_Mod_Log_ServiceLog */

        $iPageSize = $this->getParam('iNumLastSessions', 20);

        $iPage = $oReq->getInt('page', 1);
  		$oSrvAcc = &App::getModuleService('Account', 'Account');
        /* @var $oSrvAcc PhpFox_Mod_Account_ServiceAccount */
        $oSrvAcc->purgePendingTooMuchAccounts();
        list($aLastUsers, $iCnt, $iMemOnline, $iVisOnline) = $oSrvLog->getWhosOnlineInfo($iPageSize, $iPage);

		$oPager = &new Pager($iCnt, $iPage, $iPageSize);
		$iFrom = $oPager->getOffset($iPage, $iPageSize);
		$iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);

		$oTpl->assign(array(
        	'iCnt'             => $iCnt,
        	'iFrom'            => ($iCnt) ? ($iFrom + 1) : 0,
			'aPaging'          => ($iCnt) ? $oPager->getInfo($oUrl) : '',
        	'iTo'              => $iTo,
        ));

        $oTpl->assign(array(
            'aLastUsers'  => $aLastUsers,
            'iMemOnline'  => $iMemOnline,
            'iVisOnline'  => $iVisOnline,
        ));
        return $oTpl->fetch('WhosOnline.html');
    }
}
?>